public class WhileStmt extends Statement
{

	DataInfo dataInfo;
	
	private Expression expr;
	private Statement stmt;

	public WhileStmt( Expression expr, Statement st, DataInfo dataInfo )
	{

		this.expr = expr;
		this.stmt = st;
		
		this.dataInfo = dataInfo;

	}

	public String toString()
	{

		String result = "WhileStmt \n";
		String tbr = "";
		tbr += "| " + expr;
		tbr += "| " + stmt.toString();

		for( String s : tbr.split( "\n" ) )
		{
			result += "| " + s + "\n";
		}
		return result;

	}
	
	public void check() throws SemanticException {
		
		if(!expr.getType().equalsIgnoreCase("boolean"))
		{
			String details = "The condition of the while statement is not of type boolean.";
			if( dataInfo != null )
				throw new SemanticException( dataInfo.lineNumber, dataInfo.charNumber, dataInfo.line, details );
			else
				throw new SemanticException( details );
		}
			
		
		stmt.methodName = this.methodName;
		
		SymbolTable.getInstance().openScope();
		
			expr.check();
		
			stmt.check();
		
		SymbolTable.getInstance().closeScope();
		
	}

}
